home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / docs / corsoguide / format.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  1KB  |  66 lines

  1. #include <exec/types.h>
  2. #include <libraries/dosextens.h>
  3. #include <stdio.h>
  4.  
  5. void main()
  6. {
  7.   register LONG lim,rmp,cnt,grand,i,kk;
  8.  
  9.   char In[100],Out[100],str[100];
  10.   struct FileHandle *fIn,*fOut;
  11.  
  12.   printf("Limite - "); gets(In); lim = atoi(In);
  13.   printf("File in - "); gets(In);
  14.   printf("File out - "); gets(Out);
  15.  
  16.   if ((fIn = (struct FileHandle *)Open(In,MODE_OLDFILE)) == NULL)
  17.   {
  18.     printf("Errore apertura file input.\n");
  19.     exit(1);
  20.   }
  21.  
  22.   if ((fOut = (struct FileHandle *)Open(Out,MODE_NEWFILE)) == NULL)
  23.   {
  24.     printf("Errore apertura file output.\n");
  25.     Close(fIn);
  26.     exit(1);
  27.   }
  28.  
  29.   grand = Seek(fIn,0,OFFSET_END);
  30.   grand = Seek(fIn,0,OFFSET_BEGINNING);
  31.   cnt = 0;
  32.   rmp = 0;
  33.   while (grand > 0)
  34.   {
  35.     cnt = lim-rmp;
  36.     if (grand < cnt)
  37.     {
  38.       Read(fIn,str+rmp,grand);
  39.       rmp += grand; grand = 0;
  40.       Write(fOut,str,rmp);
  41.     }
  42.     else
  43.     {
  44.       Read(fIn,str+rmp,cnt);
  45.       rmp += cnt; grand -= cnt;
  46.             kk = rmp-1;
  47.       for (i=rmp-1; i>=0; i--)
  48.       {
  49.         if (*(str+i) == ' ' || *(str+i) == '\n')
  50.         {
  51.           *(str+i) = '\n';
  52.           kk = i;
  53.           i = -1;
  54.         }
  55.       }
  56.       Write(fOut,str,kk+1);
  57.       if (kk+1 < rmp)
  58.         CopyMem(str+kk+1,str,rmp-(kk+1));
  59.       rmp -= (kk+1);
  60.     }
  61.   }
  62.     Close(fOut);
  63.     Close(fIn);
  64.   exit(0);
  65. }
  66.